package com.cn.wanxi.servlet.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.service.ProductFindAllService;
import com.cn.wanxi.service.impl.ProductFindAllServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/front/product/productInformation")
public class ProductInformationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //      0.乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String productId = req.getParameter("productId");
        ProductModel productModel = new ProductModel();
        productModel.setId(Integer.parseInt(productId));
        //3.调用服务逻辑层
        ResultModel resultModel =new ResultModel();
        Map map=new HashMap();
        ProductFindAllService productFindAllService = new ProductFindAllServiceImpl();
        map.put("ProductModle",productFindAllService.getProductInformationById(productModel));
        resultModel.setData(map);
        //4.返回前端需要的数据
        resp.getWriter().print(JSONObject.toJSONString(resultModel));
    }
}
